﻿using Gp.Input;
using UnityEngine;

namespace Gp.Scripts.Core.Misc {
    // 
    public class OffsetWithMouse : MonoBehaviour {
        // private Vector3 _orgPosition;
        public float currency = 10; 
        public float amount = 1;
        private Vector2 _orgPos;
        private void Start() {
            // _orgPosition = transform.position;
            var position = transform.position;
            _orgPos = new Vector2(position.x / Screen.width, position.y / Screen.height);
        }

        private void Update() {
            var offset = Global.Get<InputManager>().GetMouseOffsetAmount(GetPos());
            var xOff = Mathf.Atan(offset.x / currency) * 1.6f * amount;
            var yOff = Mathf.Atan(offset.y / currency) * .9f * amount;

            transform.position = GetPos() + new Vector2(xOff, yOff);
        }


        private Vector2 GetPos() {
            var posX = Screen.width;
            var posY = Screen.height;
            
            
            return new Vector2(posX * _orgPos.x, posY * _orgPos.y);
        }
    }
}